package com.bcx.crm.controller.docTemplateController;

import com.bcx.crm.entity.Template;
import com.bcx.crm.plat.util.UtilTool;
import com.bcx.crm.service.docTemplateService.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by ys on 2018/3/6.
 */
@Controller
@RequestMapping("/docTemplateShow")
public class DocTemplateController {

    @Resource(name = "insertDocTemplateServiceImpl",type = InsertDocTemplateServiceImpl.class)
    private InsertDocTemplateService insertDocTemplateService;
    @Resource(name = "updateDocTemplateServiceImpl",type = UpdateDocTemplateServiceImpl.class)
    private UpdateDocTemplateService updateDocTemplateService;
    @Resource(name = "deleteDocTemplateServiceImpl", type = DeleteDocTemplateServiceImpl.class)
    private DeleteDocTemplateService deleteDocTemplateService;
    @Resource(name = "selectDocTemplateServiceImpl", type = SelectDocTemplateService.class)
    private SelectDocTemplateService selectDocTemplateService;


    @GetMapping("/init")
    public ModelAndView init(){
        ModelAndView mv = new ModelAndView("crm/thymeleaf/docTemplate/docTemplateShow");
        return mv;
    }
    @RequestMapping("/query")
    @ResponseBody
    public List<Map<String,Object>> queryList(Map<String,Object> map){
        List<Map<String,Object>> list = new ArrayList<>();
        return list;
    }
    @RequestMapping("/showTest1")
//    @ResponseBody
    public ModelAndView showTest1(Map<String,Object> map){
        ModelAndView mv = new ModelAndView("crm/thymeleaf/docTemplate/showTest1");
        return mv;
    }
    //采用BootStrap显示完整增删改查页面
    @RequestMapping("/showTest")
    public ModelAndView showTest2(Map<String,Object> map){
        return new ModelAndView("bootstrapTable-master/page/userManagement");
    }
    //BootStrap首页数据查询
    @RequestMapping("/queryTemplate")
    @ResponseBody
    public List<Template> queryTemplate(String result){
//        throw new IllegalStateException("看看抛异常是否需要相对路径");
        return selectDocTemplateService.getListTemplate(result);
    }
    @PostMapping("/insertTemplate")
    @ResponseBody
    public boolean insertDocTemplate(@RequestParam Map<String,Object> map){
        return insertDocTemplateService.insertDocTemplate(map);
    }
    @PostMapping("/updateTemplate")
    @ResponseBody
    public boolean updateTemplate(@RequestParam Map<String,Object> map){
        return updateDocTemplateService.updateDocTemplate(map);
    }
    @PostMapping("/deleteTemplate")
    @ResponseBody
    public boolean deleteTemplate(@RequestParam("rowIds") String rowIds){
        List list = UtilTool.jsonToObj(rowIds, List.class,String.class);
        return deleteDocTemplateService.deleteDocTemplateByRowIds(list);
    }
}
